import 'package:flutter/material.dart';
import 'package:flick_video_player/flick_video_player.dart';
import 'package:flutter_taotaoshipin/player/flick_multi_manager.dart';
import 'package:flutter_taotaoshipin/widget/load_image.dart';
import 'package:provider/provider.dart';

class FeedPlayerPortraitControls extends StatelessWidget {
  FeedPlayerPortraitControls({
    Key? key,
    this.flickMultiManager,
    this.flickManager,
    this.iconSize = 20,
    this.fontSize = 12,
    this.progressBarSettings,
    this.header,
    this.info,
    this.right,
    this.bottom,
    this.progressBarBottomOffset,
  }) : super(key: key);

  final FlickMultiManager? flickMultiManager;
  final FlickManager? flickManager;

  /// Icon size.
  ///
  /// This size is used for all the player icons.
  final double iconSize;

  /// Font size.
  ///
  /// This size is used for all the text.
  final double fontSize;

  /// [FlickProgressBarSettings] settings.
  final FlickProgressBarSettings? progressBarSettings;

  Widget? header;
  Widget? info;
  Widget? right;
  Widget? bottom;

  /// 进度条距离底部的偏移
  double? progressBarBottomOffset;

  @override
  Widget build(BuildContext context) {
    FlickDisplayManager displayManager =
        Provider.of<FlickDisplayManager>(context);

    return Stack(
      children: <Widget>[
        Positioned.fill(
          child: Padding(
            padding: const EdgeInsets.all(10.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                if (header != null) header!,
              ],
            ),
          ),
        ),
        Positioned.fill(
          child: FlickShowControlsAction(
            child: FlickSeekVideoAction(
              child: Center(
                child: FlickVideoBuffer(
                  child: FlickAutoHideChild(
                    showIfVideoNotInitialized: false,
                    child: FlickPlayToggle(
                      size: 74,
                      playChild: LoadAssetImage(
                        'player/play',
                        width: 74,
                        height: 74,
                      ),
                      pauseChild: LoadAssetImage(
                        'player/pause',
                        width: 74,
                        height: 74,
                      ),
                      replayChild: LoadAssetImage(
                        'player/play',
                        width: 74,
                        height: 74,
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
        Positioned.fill(
          top: 0,
          right: 0,
          bottom: 200,
          child: Padding(
            padding: const EdgeInsets.all(10.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                if (right != null) right!,
              ],
            ),
          ),
        ),
        Positioned(
          left: 0,
          right: 0,
          bottom: 0,
          child: FlickAutoHideChild(
            autoHide: false,
            showIfVideoNotInitialized: true,
            child: SafeArea(
              child: Container(
                // padding: const EdgeInsets.all(10.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    if (info != null) info!,
                    Padding(
                      padding: EdgeInsets.only(
                        bottom: progressBarBottomOffset ?? 0,
                        left: 15,
                        right: 15,
                      ),
                      child: FlickVideoProgressBar(
                        flickProgressBarSettings: progressBarSettings,
                      ),
                    ),
                    if (bottom != null) bottom!,
                  ],
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
